home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 1998 November / IRIX 6.5.2 Base Documentation November 1998.img / usr / share / catman / u_man / cat1 / perlsub.z / perlsub
Text File  |  1998-10-30  |  48KB  |  1,255 lines

  1.  
  2.  
  3.  
  4. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      perlsub - Perl subroutines
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      To declare subroutines:
  13.  
  14.          sub NAME;             # A "forward" declaration.
  15.          sub NAME(PROTO);      #  ditto, but with prototypes
  16.  
  17.          sub NAME BLOCK        # A declaration and a definition.
  18.          sub NAME(PROTO) BLOCK #  ditto, but with prototypes
  19.  
  20.      To define an anonymous subroutine at runtime:
  21.  
  22.          $subref = sub BLOCK;
  23.  
  24.      To import subroutines:
  25.  
  26.          use PACKAGE qw(NAME1 NAME2 NAME3);
  27.  
  28.      To call subroutines:
  29.  
  30.          NAME(LIST);    # & is optional with parentheses.
  31.          NAME LIST;     # Parentheses optional if predeclared/imported.
  32.          &NAME;         # Passes current @_ to subroutine.
  33.  
  34.  
  35. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  36.      Like many languages, Perl provides for user-defined subroutines.  These
  37.      may be located anywhere in the main program, loaded in from other files
  38.      via the do, require, or use keywords, or even generated on the fly using
  39.      eval or anonymous subroutines (closures).  You can even call a function
  40.      indirectly using a variable containing its name or a CODE reference to
  41.      it, as in $var = \&function.
  42.  
  43.      The Perl model for function call and return values is simple: all
  44.      functions are passed as parameters one single flat list of scalars, and
  45.      all functions likewise return to their caller one single flat list of
  46.      scalars.  Any arrays or hashes in these call and return lists will
  47.      collapse, losing their identities--but you may always use pass-by-
  48.      reference instead to avoid this.  Both call and return lists may contain
  49.      as many or as few scalar elements as you'd like.  (Often a function
  50.      without an explicit return statement is called a subroutine, but there's
  51.      really no difference from the language's perspective.)
  52.  
  53.      Any arguments passed to the routine come in as the array @_.  Thus if you
  54.      called a function with two arguments, those would be stored in $_[0] and
  55.      $_[1].  The array @_ is a local array, but its elements are aliases for
  56.      the actual scalar parameters.  In particular, if an element $_[0] is
  57.      updated, the corresponding argument is updated (or an error occurs if it
  58.      is not updatable).  If an argument is an array or hash element which did
  59.      not exist when the function was called, that element is created only when
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  71.  
  72.  
  73.  
  74.      (and if) it is modified or if a reference to it is taken.  (Some earlier
  75.      versions of Perl created the element whether or not it was assigned to.)
  76.      Note that assigning to the whole array @_ removes the aliasing, and does
  77.      not update any arguments.
  78.  
  79.      The return value of the subroutine is the value of the last expression
  80.      evaluated.  Alternatively, a return statement may be used to exit the
  81.      subroutine, optionally specifying the returned value, which will be
  82.      evaluated in the appropriate context (list, scalar, or void) depending on
  83.      the context of the subroutine call.  If you specify no return value, the
  84.      subroutine will return an empty list in a list context, an undefined
  85.      value in a scalar context, or nothing in a void context.  If you return
  86.      one or more arrays and/or hashes, these will be flattened together into
  87.      one large indistinguishable list.
  88.  
  89.      Perl does not have named formal parameters, but in practice all you do is
  90.      assign to a _m_y() list of these.  Any variables you use in the function
  91.      that aren't declared private are global variables.  For the gory details
  92.      on creating private variables, see the section on _P_r_i_v_a_t_e _V_a_r_i_a_b_l_e_s _v_i_a
  93.      _m_y() and the section on _T_e_m_p_o_r_a_r_y _V_a_l_u_e_s _v_i_a _l_o_c_a_l().  To create
  94.      protected environments for a set of functions in a separate package (and
  95.      probably a separate file), see the section on _P_a_c_k_a_g_e_s in the _p_e_r_l_m_o_d
  96.      manpage.
  97.  
  98.      Example:
  99.  
  100.          sub max {
  101.              my $max = shift(@_);
  102.              foreach $foo (@_) {
  103.                  $max = $foo if $max < $foo;
  104.              }
  105.              return $max;
  106.          }
  107.          $bestday = max($mon,$tue,$wed,$thu,$fri);
  108.  
  109.      Example:
  110.  
  111.          # get a line, combining continuation lines
  112.          #  that start with whitespace
  113.  
  114.          sub get_line {
  115.              $thisline = $lookahead;  # GLOBAL VARIABLES!!
  116.              LINE: while (defined($lookahead = <STDIN>)) {
  117.                  if ($lookahead =~ /^[ \t]/) {
  118.                      $thisline .= $lookahead;
  119.                  }
  120.                  else {
  121.                      last LINE;
  122.                  }
  123.              }
  124.              $thisline;
  125.          }
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  137.  
  138.  
  139.  
  140.          $lookahead = <STDIN>;       # get first line
  141.          while ($_ = get_line()) {
  142.              ...
  143.          }
  144.  
  145.      Use array assignment to a local list to name your formal arguments:
  146.  
  147.          sub maybeset {
  148.              my($key, $value) = @_;
  149.              $Foo{$key} = $value unless $Foo{$key};
  150.          }
  151.  
  152.      This also has the effect of turning call-by-reference into call-by-value,
  153.      because the assignment copies the values.  Otherwise a function is free
  154.      to do in-place modifications of @_ and change its caller's values.
  155.  
  156.          upcase_in($v1, $v2);  # this changes $v1 and $v2
  157.          sub upcase_in {
  158.              for (@_) { tr/a-z/A-Z/ }
  159.          }
  160.  
  161.      You aren't allowed to modify constants in this way, of course.  If an
  162.      argument were actually literal and you tried to change it, you'd take a
  163.      (presumably fatal) exception.   For example, this won't work:
  164.  
  165.          upcase_in("frederick");
  166.  
  167.      It would be much safer if the _u_p_c_a_s_e__i_n() function were written to return
  168.      a copy of its parameters instead of changing them in place:
  169.  
  170.          ($v3, $v4) = upcase($v1, $v2);  # this doesn't
  171.          sub upcase {
  172.              return unless defined wantarray;  # void context, do nothing
  173.              my @parms = @_;
  174.              for (@parms) { tr/a-z/A-Z/ }
  175.              return wantarray ? @parms : $parms[0];
  176.          }
  177.  
  178.      Notice how this (unprototyped) function doesn't care whether it was
  179.      passed real scalars or arrays.  Perl will see everything as one big long
  180.      flat @_ parameter list.  This is one of the ways where Perl's simple
  181.      argument-passing style shines.  The _u_p_c_a_s_e() function would work
  182.      perfectly well without changing the _u_p_c_a_s_e() definition even if we fed it
  183.      things like this:
  184.  
  185.          @newlist   = upcase(@list1, @list2);
  186.          @newlist   = upcase( split /:/, $var );
  187.  
  188.      Do not, however, be tempted to do this:
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  203.  
  204.  
  205.  
  206.          (@a, @b)   = upcase(@list1, @list2);
  207.  
  208.      Because like its flat incoming parameter list, the return list is also
  209.      flat.  So all you have managed to do here is stored everything in @a and
  210.      made @b an empty list.  See the section on /"_P_a_s_s _b_y _R_e_f_e_r_e_n_c_e for
  211.      alternatives.
  212.  
  213.      A subroutine may be called using the "&" prefix.  The "&" is optional in
  214.      modern Perls, and so are the parentheses if the subroutine has been
  215.      predeclared.  (Note, however, that the "&" is _N_O_T optional when you're
  216.      just naming the subroutine, such as when it's used as an argument to
  217.      _d_e_f_i_n_e_d() or _u_n_d_e_f().  Nor is it optional when you want to do an indirect
  218.      subroutine call with a subroutine name or reference using the &$subref()
  219.      or &{$subref}() constructs.  See the _p_e_r_l_r_e_f manpage for more on that.)
  220.  
  221.      Subroutines may be called recursively.  If a subroutine is called using
  222.      the "&" form, the argument list is optional, and if omitted, no @_ array
  223.      is set up for the subroutine: the @_ array at the time of the call is
  224.      visible to subroutine instead.  This is an efficiency mechanism that new
  225.      users may wish to avoid.
  226.  
  227.          &foo(1,2,3);        # pass three arguments
  228.          foo(1,2,3);         # the same
  229.  
  230.          foo();              # pass a null list
  231.          &foo();             # the same
  232.  
  233.          &foo;               # foo() get current args, like foo(@_) !!
  234.          foo;                # like foo() IFF sub foo predeclared, else "foo"
  235.  
  236.      Not only does the "&" form make the argument list optional, but it also
  237.      disables any prototype checking on the arguments you do provide.  This is
  238.      partly for historical reasons, and partly for having a convenient way to
  239.      cheat if you know what you're doing.  See the section on Prototypes
  240.      below.
  241.  
  242.      PPPPrrrriiiivvvvaaaatttteeee VVVVaaaarrrriiiiaaaabbbblllleeeessss vvvviiiiaaaa _m_y()
  243.  
  244.      Synopsis:
  245.  
  246.          my $foo;            # declare $foo lexically local
  247.          my (@wid, %get);    # declare list of variables local
  248.          my $foo = "flurp";  # declare $foo lexical, and init it
  249.          my @oof = @bar;     # declare @oof lexical, and init it
  250.  
  251.      A "my" declares the listed variables to be confined (lexically) to the
  252.      enclosing block, conditional (if/unless/elsif/else), loop
  253.      (for/foreach/while/until/continue), subroutine, eval, or do/require/use'd
  254.      file.  If more than one value is listed, the list must be placed in
  255.      parentheses.  All listed elements must be legal lvalues.  Only
  256.      alphanumeric identifiers may be lexically scoped--magical builtins like
  257.      $/ must currently be localized with "local" instead.
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  269.  
  270.  
  271.  
  272.      Unlike dynamic variables created by the "local" statement, lexical
  273.      variables declared with "my" are totally hidden from the outside world,
  274.      including any called subroutines (even if it's the same subroutine called
  275.      from itself or elsewhere--every call gets its own copy).
  276.  
  277.      (An _e_v_a_l(), however, can see the lexical variables of the scope it is
  278.      being evaluated in so long as the names aren't hidden by declarations
  279.      within the _e_v_a_l() itself.  See the _p_e_r_l_r_e_f manpage.)
  280.  
  281.      The parameter list to _m_y() may be assigned to if desired, which allows
  282.      you to initialize your variables.  (If no initializer is given for a
  283.      particular variable, it is created with the undefined value.)  Commonly
  284.      this is used to name the parameters to a subroutine.  Examples:
  285.  
  286.          $arg = "fred";        # "global" variable
  287.          $n = cube_root(27);
  288.          print "$arg thinks the root is $n\n";
  289.       fred thinks the root is 3
  290.  
  291.          sub cube_root {
  292.              my $arg = shift;  # name doesn't matter
  293.              $arg **= 1/3;
  294.              return $arg;
  295.          }
  296.  
  297.      The "my" is simply a modifier on something you might assign to.  So when
  298.      you do assign to the variables in its argument list, the "my" doesn't
  299.      change whether those variables is viewed as a scalar or an array.  So
  300.  
  301.          my ($foo) = <STDIN>;
  302.          my @FOO = <STDIN>;
  303.  
  304.      both supply a list context to the right-hand side, while
  305.  
  306.          my $foo = <STDIN>;
  307.  
  308.      supplies a scalar context.  But the following declares only one variable:
  309.  
  310.          my $foo, $bar = 1;
  311.  
  312.      That has the same effect as
  313.  
  314.          my $foo;
  315.          $bar = 1;
  316.  
  317.      The declared variable is not introduced (is not visible) until after the
  318.      current statement.  Thus,
  319.  
  320.          my $x = $x;
  321.  
  322.      can be used to initialize the new $x with the value of the old $x, and
  323.      the expression
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  335.  
  336.  
  337.  
  338.          my $x = 123 and $x == 123
  339.  
  340.      is false unless the old $x happened to have the value 123.
  341.  
  342.      Lexical scopes of control structures are not bounded precisely by the
  343.      braces that delimit their controlled blocks; control expressions are part
  344.      of the scope, too.  Thus in the loop
  345.  
  346.          while (defined(my $line = <>)) {
  347.              $line = lc $line;
  348.          } continue {
  349.              print $line;
  350.          }
  351.  
  352.      the scope of $line extends from its declaration throughout the rest of
  353.      the loop construct (including the continue clause), but not beyond it.
  354.      Similarly, in the conditional
  355.  
  356.          if ((my $answer = <STDIN>) =~ /^yes$/i) {
  357.              user_agrees();
  358.          } elsif ($answer =~ /^no$/i) {
  359.              user_disagrees();
  360.          } else {
  361.              chomp $answer;
  362.              die "'$answer' is neither 'yes' nor 'no'";
  363.          }
  364.  
  365.      the scope of $answer extends from its declaration throughout the rest of
  366.      the conditional (including elsif and else clauses, if any), but not
  367.      beyond it.
  368.  
  369.      (None of the foregoing applies to if/unless or while/until modifiers
  370.      appended to simple statements.  Such modifiers are not control structures
  371.      and have no effect on scoping.)
  372.  
  373.      The foreach loop defaults to scoping its index variable dynamically (in
  374.      the manner of local; see below).  However, if the index variable is
  375.      prefixed with the keyword "my", then it is lexically scoped instead.
  376.      Thus in the loop
  377.  
  378.          for my $i (1, 2, 3) {
  379.              some_function();
  380.          }
  381.  
  382.      the scope of $i extends to the end of the loop, but not beyond it, and so
  383.      the value of $i is unavailable in _s_o_m_e__f_u_n_c_t_i_o_n().
  384.  
  385.      Some users may wish to encourage the use of lexically scoped variables.
  386.      As an aid to catching implicit references to package variables, if you
  387.      say
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  401.  
  402.  
  403.  
  404.          use strict 'vars';
  405.  
  406.      then any variable reference from there to the end of the enclosing block
  407.      must either refer to a lexical variable, or must be fully qualified with
  408.      the package name.  A compilation error results otherwise.  An inner block
  409.      may countermand this with "no strict 'vars'".
  410.  
  411.      A _m_y() has both a compile-time and a run-time effect.  At compile time,
  412.      the compiler takes notice of it; the principle usefulness of this is to
  413.      quiet use strict 'vars'.  The actual initialization is delayed until run
  414.      time, so it gets executed appropriately; every time through a loop, for
  415.      example.
  416.  
  417.      Variables declared with "my" are not part of any package and are
  418.      therefore never fully qualified with the package name.  In particular,
  419.      you're not allowed to try to make a package variable (or other global)
  420.      lexical:
  421.  
  422.          my $pack::var;      # ERROR!  Illegal syntax
  423.          my $_;              # also illegal (currently)
  424.  
  425.      In fact, a dynamic variable (also known as package or global variables)
  426.      are still accessible using the fully qualified :: notation even while a
  427.      lexical of the same name is also visible:
  428.  
  429.          package main;
  430.          local $x = 10;
  431.          my    $x = 20;
  432.          print "$x and $::x\n";
  433.  
  434.      That will print out 20 and 10.
  435.  
  436.      You may declare "my" variables at the outermost scope of a file to hide
  437.      any such identifiers totally from the outside world.  This is similar to
  438.      C's static variables at the file level.  To do this with a subroutine
  439.      requires the use of a closure (anonymous function).  If a block (such as
  440.      an _e_v_a_l(), function, or package) wants to create a private subroutine
  441.      that cannot be called from outside that block, it can declare a lexical
  442.      variable containing an anonymous sub reference:
  443.  
  444.          my $secret_version = '1.001-beta';
  445.          my $secret_sub = sub { print $secret_version };
  446.          &$secret_sub();
  447.  
  448.      As long as the reference is never returned by any function within the
  449.      module, no outside module can see the subroutine, because its name is not
  450.      in any package's symbol table.  Remember that it's not _R_E_A_L_L_Y called
  451.      $some_pack::secret_version or anything; it's just $secret_version,
  452.      unqualified and unqualifiable.
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  467.  
  468.  
  469.  
  470.      This does not work with object methods, however; all object methods have
  471.      to be in the symbol table of some package to be found.
  472.  
  473.      Just because the lexical variable is lexically (also called statically)
  474.      scoped doesn't mean that within a function it works like a C static.  It
  475.      normally works more like a C auto.  But here's a mechanism for giving a
  476.      function private variables with both lexical scoping and a static
  477.      lifetime.  If you do want to create something like C's static variables,
  478.      just enclose the whole function in an extra block, and put the static
  479.      variable outside the function but in the block.
  480.  
  481.          {
  482.              my $secret_val = 0;
  483.              sub gimme_another {
  484.                  return ++$secret_val;
  485.              }
  486.          }
  487.          # $secret_val now becomes unreachable by the outside
  488.          # world, but retains its value between calls to gimme_another
  489.  
  490.      If this function is being sourced in from a separate file via require or
  491.      use, then this is probably just fine.  If it's all in the main program,
  492.      you'll need to arrange for the _m_y() to be executed early, either by
  493.      putting the whole block above your main program, or more likely, placing
  494.      merely a BEGIN sub around it to make sure it gets executed before your
  495.      program starts to run:
  496.  
  497.          sub BEGIN {
  498.              my $secret_val = 0;
  499.              sub gimme_another {
  500.                  return ++$secret_val;
  501.              }
  502.          }
  503.  
  504.      See the _p_e_r_l_r_u_n manpage about the BEGIN function.
  505.  
  506.      TTTTeeeemmmmppppoooorrrraaaarrrryyyy VVVVaaaalllluuuueeeessss vvvviiiiaaaa _l_o_c_a_l()
  507.  
  508.      NNNNOOOOTTTTEEEE: In general, you should be using "my" instead of "local", because
  509.      it's faster and safer.  Exceptions to this include the global punctuation
  510.      variables, filehandles and formats, and direct manipulation of the Perl
  511.      symbol table itself.  Format variables often use "local" though, as do
  512.      other variables whose current value must be visible to called
  513.      subroutines.
  514.  
  515.      Synopsis:
  516.  
  517.          local $foo;                 # declare $foo dynamically local
  518.          local (@wid, %get);         # declare list of variables local
  519.          local $foo = "flurp";       # declare $foo dynamic, and init it
  520.          local @oof = @bar;          # declare @oof dynamic, and init it
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  533.  
  534.  
  535.  
  536.          local *FH;                  # localize $FH, @FH, %FH, &FH  ...
  537.          local *merlyn = *randal;    # now $merlyn is really $randal, plus
  538.                                      #     @merlyn is really @randal, etc
  539.          local *merlyn = 'randal';   # SAME THING: promote 'randal' to *randal
  540.          local *merlyn = \$randal;   # just alias $merlyn, not @merlyn etc
  541.  
  542.      A _l_o_c_a_l() modifies its listed variables to be local to the enclosing
  543.      block, (or subroutine, eval{}, or do) and _a_n_y _c_a_l_l_e_d _f_r_o_m _w_i_t_h_i_n _t_h_a_t
  544.      _b_l_o_c_k.  A _l_o_c_a_l() just gives temporary values to global (meaning package)
  545.      variables.  This is known as dynamic scoping.  Lexical scoping is done
  546.      with "my", which works more like C's auto declarations.
  547.  
  548.      If more than one variable is given to _l_o_c_a_l(), they must be placed in
  549.      parentheses.  All listed elements must be legal lvalues.  This operator
  550.      works by saving the current values of those variables in its argument
  551.      list on a hidden stack and restoring them upon exiting the block,
  552.      subroutine, or eval.  This means that called subroutines can also
  553.      reference the local variable, but not the global one.  The argument list
  554.      may be assigned to if desired, which allows you to initialize your local
  555.      variables.  (If no initializer is given for a particular variable, it is
  556.      created with an undefined value.)  Commonly this is used to name the
  557.      parameters to a subroutine.  Examples:
  558.  
  559.          for $i ( 0 .. 9 ) {
  560.              $digits{$i} = $i;
  561.          }
  562.          # assume this function uses global %digits hash
  563.          parse_num();
  564.  
  565.          # now temporarily add to %digits hash
  566.          if ($base12) {
  567.              # (NOTE: not claiming this is efficient!)
  568.              local %digits  = (%digits, 't' => 10, 'e' => 11);
  569.              parse_num();  # parse_num gets this new %digits!
  570.          }
  571.          # old %digits restored here
  572.  
  573.      Because _l_o_c_a_l() is a run-time command, it gets executed every time
  574.      through a loop.  In releases of Perl previous to 5.0, this used more
  575.      stack storage each time until the loop was exited.  Perl now reclaims the
  576.      space each time through, but it's still more efficient to declare your
  577.      variables outside the loop.
  578.  
  579.      A local is simply a modifier on an lvalue expression.  When you assign to
  580.      a localized variable, the local doesn't change whether its list is viewed
  581.      as a scalar or an array.  So
  582.  
  583.          local($foo) = <STDIN>;
  584.          local @FOO = <STDIN>;
  585.  
  586.      both supply a list context to the right-hand side, while
  587.  
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  599.  
  600.  
  601.  
  602.          local $foo = <STDIN>;
  603.  
  604.      supplies a scalar context.
  605.  
  606.      A note about local() and composite types is in order.  Something like
  607.      local(%foo) works by temporarily placing a brand new hash in the symbol
  608.      table.  The old hash is left alone, but is hidden "behind" the new one.
  609.  
  610.      This means the old variable is completely invisible via the symbol table
  611.      (i.e. the hash entry in the *foo typeglob) for the duration of the
  612.      dynamic scope within which the local() was seen.  This has the effect of
  613.      allowing one to temporarily occlude any magic on composite types.  For
  614.      instance, this will briefly alter a tied hash to some other
  615.      implementation:
  616.  
  617.          tie %ahash, 'APackage';
  618.          [...]
  619.          {
  620.             local %ahash;
  621.             tie %ahash, 'BPackage';
  622.             [..called code will see %ahash tied to 'BPackage'..]
  623.             {
  624.                local %ahash;
  625.                [..%ahash is a normal (untied) hash here..]
  626.             }
  627.          }
  628.          [..%ahash back to its initial tied self again..]
  629.  
  630.      As another example, a custom implementation of %ENV might look like this:
  631.  
  632.          {
  633.              local %ENV;
  634.              tie %ENV, 'MyOwnEnv';
  635.              [..do your own fancy %ENV manipulation here..]
  636.          }
  637.          [..normal %ENV behavior here..]
  638.  
  639.  
  640.      PPPPaaaassssssssiiiinnnngggg SSSSyyyymmmmbbbboooollll TTTTaaaabbbblllleeee EEEEnnnnttttrrrriiiieeeessss ((((ttttyyyyppppeeeegggglllloooobbbbssss))))
  641.  
  642.      [Note:  The mechanism described in this section was originally the only
  643.      way to simulate pass-by-reference in older versions of Perl.  While it
  644.      still works fine in modern versions, the new reference mechanism is
  645.      generally easier to work with.  See below.]
  646.  
  647.      Sometimes you don't want to pass the value of an array to a subroutine
  648.      but rather the name of it, so that the subroutine can modify the global
  649.      copy of it rather than working with a local copy.  In perl you can refer
  650.      to all objects of a particular name by prefixing the name with a star:
  651.      *foo.  This is often known as a "typeglob", because the star on the front
  652.      can be thought of as a wildcard match for all the funny prefix characters
  653.      on variables and subroutines and such.
  654.  
  655.  
  656.  
  657.                                                                        PPPPaaaaggggeeee 11110000
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  665.  
  666.  
  667.  
  668.      When evaluated, the typeglob produces a scalar value that represents all
  669.      the objects of that name, including any filehandle, format, or
  670.      subroutine.  When assigned to, it causes the name mentioned to refer to
  671.      whatever "*" value was assigned to it.  Example:
  672.  
  673.          sub doubleary {
  674.              local(*someary) = @_;
  675.              foreach $elem (@someary) {
  676.                  $elem *= 2;
  677.              }
  678.          }
  679.          doubleary(*foo);
  680.          doubleary(*bar);
  681.  
  682.      Note that scalars are already passed by reference, so you can modify
  683.      scalar arguments without using this mechanism by referring explicitly to
  684.      $_[0] etc.  You can modify all the elements of an array by passing all
  685.      the elements as scalars, but you have to use the * mechanism (or the
  686.      equivalent reference mechanism) to push, pop, or change the size of an
  687.      array.  It will certainly be faster to pass the typeglob (or reference).
  688.  
  689.      Even if you don't want to modify an array, this mechanism is useful for
  690.      passing multiple arrays in a single LIST, because normally the LIST
  691.      mechanism will merge all the array values so that you can't extract out
  692.      the individual arrays.  For more on typeglobs, see the section on
  693.      _T_y_p_e_g_l_o_b_s _a_n_d _F_i_l_e_h_a_n_d_l_e_s in the _p_e_r_l_d_a_t_a manpage.
  694.  
  695.      PPPPaaaassssssss bbbbyyyy RRRReeeeffffeeeerrrreeeennnncccceeee
  696.  
  697.      If you want to pass more than one array or hash into a function--or
  698.      return them from it--and have them maintain their integrity, then you're
  699.      going to have to use an explicit pass-by-reference.  Before you do that,
  700.      you need to understand references as detailed in the _p_e_r_l_r_e_f manpage.
  701.      This section may not make much sense to you otherwise.
  702.  
  703.      Here are a few simple examples.  First, let's pass in several arrays to a
  704.      function and have it pop all of then, return a new list of all their
  705.      former last elements:
  706.  
  707.          @tailings = popmany ( \@a, \@b, \@c, \@d );
  708.  
  709.          sub popmany {
  710.              my $aref;
  711.              my @retlist = ();
  712.              foreach $aref ( @_ ) {
  713.                  push @retlist, pop @$aref;
  714.              }
  715.              return @retlist;
  716.          }
  717.  
  718.      Here's how you might write a function that returns a list of keys
  719.      occurring in all the hashes passed to it:
  720.  
  721.  
  722.  
  723.                                                                        PPPPaaaaggggeeee 11111111
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  731.  
  732.  
  733.  
  734.          @common = inter( \%foo, \%bar, \%joe );
  735.          sub inter {
  736.              my ($k, $href, %seen); # locals
  737.              foreach $href (@_) {
  738.                  while ( $k = each %$href ) {
  739.                      $seen{$k}++;
  740.                  }
  741.              }
  742.              return grep { $seen{$_} == @_ } keys %seen;
  743.          }
  744.  
  745.      So far, we're using just the normal list return mechanism.  What happens
  746.      if you want to pass or return a hash?  Well, if you're using only one of
  747.      them, or you don't mind them concatenating, then the normal calling
  748.      convention is ok, although a little expensive.
  749.  
  750.      Where people get into trouble is here:
  751.  
  752.          (@a, @b) = func(@c, @d);
  753.      or
  754.          (%a, %b) = func(%c, %d);
  755.  
  756.      That syntax simply won't work.  It sets just @a or %a and clears the @b
  757.      or %b.  Plus the function didn't get passed into two separate arrays or
  758.      hashes: it got one long list in @_, as always.
  759.  
  760.      If you can arrange for everyone to deal with this through references,
  761.      it's cleaner code, although not so nice to look at.  Here's a function
  762.      that takes two array references as arguments, returning the two array
  763.      elements in order of how many elements they have in them:
  764.  
  765.          ($aref, $bref) = func(\@c, \@d);
  766.          print "@$aref has more than @$bref\n";
  767.          sub func {
  768.              my ($cref, $dref) = @_;
  769.              if (@$cref > @$dref) {
  770.                  return ($cref, $dref);
  771.              } else {
  772.                  return ($dref, $cref);
  773.              }
  774.          }
  775.  
  776.      It turns out that you can actually do this also:
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.                                                                        PPPPaaaaggggeeee 11112222
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  797.  
  798.  
  799.  
  800.          (*a, *b) = func(\@c, \@d);
  801.          print "@a has more than @b\n";
  802.          sub func {
  803.              local (*c, *d) = @_;
  804.              if (@c > @d) {
  805.                  return (\@c, \@d);
  806.              } else {
  807.                  return (\@d, \@c);
  808.              }
  809.          }
  810.  
  811.      Here we're using the typeglobs to do symbol table aliasing.  It's a tad
  812.      subtle, though, and also won't work if you're using _m_y() variables,
  813.      because only globals (well, and _l_o_c_a_l()s) are in the symbol table.
  814.  
  815.      If you're passing around filehandles, you could usually just use the bare
  816.      typeglob, like *STDOUT, but typeglobs references would be better because
  817.      they'll still work properly under use strict 'refs'.  For example:
  818.  
  819.          splutter(\*STDOUT);
  820.          sub splutter {
  821.              my $fh = shift;
  822.              print $fh "her um well a hmmm\n";
  823.          }
  824.  
  825.          $rec = get_rec(\*STDIN);
  826.          sub get_rec {
  827.              my $fh = shift;
  828.              return scalar <$fh>;
  829.          }
  830.  
  831.      Another way to do this is using *HANDLE{IO}, see the _p_e_r_l_r_e_f manpage for
  832.      usage and caveats.
  833.  
  834.      If you're planning on generating new filehandles, you could do this:
  835.  
  836.          sub openit {
  837.              my $name = shift;
  838.              local *FH;
  839.              return open (FH, $path) ? *FH : undef;
  840.          }
  841.  
  842.      Although that will actually produce a small memory leak.  See the bottom
  843.      of the open() entry in the _p_e_r_l_f_u_n_c manpage for a somewhat cleaner way
  844.      using the IO::Handle package.
  845.  
  846.      PPPPrrrroooottttoooottttyyyyppppeeeessss
  847.  
  848.      As of the 5.002 release of perl, if you declare
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.                                                                        PPPPaaaaggggeeee 11113333
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  863.  
  864.  
  865.  
  866.          sub mypush (\@@)
  867.  
  868.      then _m_y_p_u_s_h() takes arguments exactly like _p_u_s_h() does.  The declaration
  869.      of the function to be called must be visible at compile time.  The
  870.      prototype affects only the interpretation of new-style calls to the
  871.      function, where new-style is defined as not using the & character.  In
  872.      other words, if you call it like a builtin function, then it behaves like
  873.      a builtin function.  If you call it like an old-fashioned subroutine,
  874.      then it behaves like an old-fashioned subroutine.  It naturally falls out
  875.      from this rule that prototypes have no influence on subroutine references
  876.      like \&foo or on indirect subroutine calls like &{$subref}.
  877.  
  878.      Method calls are not influenced by prototypes either, because the
  879.      function to be called is indeterminate at compile time, because it
  880.      depends on inheritance.
  881.  
  882.      Because the intent is primarily to let you define subroutines that work
  883.      like builtin commands, here are the prototypes for some other functions
  884.      that parse almost exactly like the corresponding builtins.
  885.  
  886.          Declared as                 Called as
  887.  
  888.          sub mylink ($$)             mylink $old, $new
  889.          sub myvec ($$$)             myvec $var, $offset, 1
  890.          sub myindex ($$;$)          myindex &getstring, "substr"
  891.          sub mysyswrite ($$$;$)      mysyswrite $buf, 0, length($buf) - $off, $off
  892.          sub myreverse (@)           myreverse $a,$b,$c
  893.          sub myjoin ($@)             myjoin ":",$a,$b,$c
  894.          sub mypop (\@)              mypop @array
  895.          sub mysplice (\@$$@)        mysplice @array,@array,0,@pushme
  896.          sub mykeys (\%)             mykeys %{$hashref}
  897.          sub myopen (*;$)            myopen HANDLE, $name
  898.          sub mypipe (**)             mypipe READHANDLE, WRITEHANDLE
  899.          sub mygrep (&@)             mygrep { /foo/ } $a,$b,$c
  900.          sub myrand ($)              myrand 42
  901.          sub mytime ()               mytime
  902.  
  903.      Any backslashed prototype character represents an actual argument that
  904.      absolutely must start with that character.  The value passed to the
  905.      subroutine (as part of @_) will be a reference to the actual argument
  906.      given in the subroutine call, obtained by applying \ to that argument.
  907.  
  908.      Unbackslashed prototype characters have special meanings.  Any
  909.      unbackslashed @ or % eats all the rest of the arguments, and forces list
  910.      context.  An argument represented by $ forces scalar context.  An &
  911.      requires an anonymous subroutine, which, if passed as the first argument,
  912.      does not require the "sub" keyword or a subsequent comma.  A * does
  913.      whatever it has to do to turn the argument into a reference to a symbol
  914.      table entry.
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.                                                                        PPPPaaaaggggeeee 11114444
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  929.  
  930.  
  931.  
  932.      A semicolon separates mandatory arguments from optional arguments.  (It
  933.      is redundant before @ or %.)
  934.  
  935.      Note how the last three examples above are treated specially by the
  936.      parser.  _m_y_g_r_e_p() is parsed as a true list operator, _m_y_r_a_n_d() is parsed
  937.      as a true unary operator with unary precedence the same as _r_a_n_d(), and
  938.      _m_y_t_i_m_e() is truly without arguments, just like _t_i_m_e().  That is, if you
  939.      say
  940.  
  941.          mytime +2;
  942.  
  943.      you'll get _m_y_t_i_m_e() + 2, not _m_y_t_i_m_e(2), which is how it would be parsed
  944.      without the prototype.
  945.  
  946.      The interesting thing about & is that you can generate new syntax with
  947.      it:
  948.  
  949.          sub try (&@) {
  950.              my($try,$catch) = @_;
  951.              eval { &$try };
  952.              if ($@) {
  953.                  local $_ = $@;
  954.                  &$catch;
  955.              }
  956.          }
  957.          sub catch (&) { $_[0] }
  958.  
  959.          try {
  960.              die "phooey";
  961.          } catch {
  962.              /phooey/ and print "unphooey\n";
  963.          };
  964.  
  965.      That prints "unphooey".  (Yes, there are still unresolved issues having
  966.      to do with the visibility of @_.  I'm ignoring that question for the
  967.      moment.  (But note that if we make @_ lexically scoped, those anonymous
  968.      subroutines can act like closures... (Gee, is this sounding a little
  969.      Lispish?  (Never mind.))))
  970.  
  971.      And here's a reimplementation of grep:
  972.  
  973.          sub mygrep (&@) {
  974.              my $code = shift;
  975.              my @result;
  976.              foreach $_ (@_) {
  977.                  push(@result, $_) if &$code;
  978.              }
  979.              @result;
  980.          }
  981.  
  982.      Some folks would prefer full alphanumeric prototypes.  Alphanumerics have
  983.      been intentionally left out of prototypes for the express purpose of
  984.  
  985.  
  986.  
  987.                                                                        PPPPaaaaggggeeee 11115555
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  995.  
  996.  
  997.  
  998.      someday in the future adding named, formal parameters.  The current
  999.      mechanism's main goal is to let module writers provide better diagnostics
  1000.      for module users.  Larry feels the notation quite understandable to Perl
  1001.      programmers, and that it will not intrude greatly upon the meat of the
  1002.      module, nor make it harder to read.  The line noise is visually
  1003.      encapsulated into a small pill that's easy to swallow.
  1004.  
  1005.      It's probably best to prototype new functions, not retrofit prototyping
  1006.      into older ones.  That's because you must be especially careful about
  1007.      silent impositions of differing list versus scalar contexts.  For
  1008.      example, if you decide that a function should take just one parameter,
  1009.      like this:
  1010.  
  1011.          sub func ($) {
  1012.              my $n = shift;
  1013.              print "you gave me $n\n";
  1014.          }
  1015.  
  1016.      and someone has been calling it with an array or expression returning a
  1017.      list:
  1018.  
  1019.          func(@foo);
  1020.          func( split /:/ );
  1021.  
  1022.      Then you've just supplied an automatic _s_c_a_l_a_r() in front of their
  1023.      argument, which can be more than a bit surprising.  The old @foo which
  1024.      used to hold one thing doesn't get passed in.  Instead, the _f_u_n_c() now
  1025.      gets passed in 1, that is, the number of elements in @foo.  And the
  1026.      _s_p_l_i_t() gets called in a scalar context and starts scribbling on your @_
  1027.      parameter list.
  1028.  
  1029.      This is all very powerful, of course, and should be used only in
  1030.      moderation to make the world a better place.
  1031.  
  1032.      CCCCoooonnnnssssttttaaaannnntttt FFFFuuuunnnnccccttttiiiioooonnnnssss
  1033.  
  1034.      Functions with a prototype of () are potential candidates for inlining.
  1035.      If the result after optimization and constant folding is either a
  1036.      constant or a lexically-scoped scalar which has no other references, then
  1037.      it will be used in place of function calls made without & or do. Calls
  1038.      made using & or do are never inlined.  (See constant.pm for an easy way
  1039.      to declare most constants.)
  1040.  
  1041.      All of the following functions would be inlined.
  1042.  
  1043.          sub pi ()           { 3.14159 }             # Not exact, but close.
  1044.          sub PI ()           { 4 * atan2 1, 1 }      # As good as it gets,
  1045.                                                      # and it's inlined, too!
  1046.          sub ST_DEV ()       { 0 }
  1047.          sub ST_INO ()       { 1 }
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.                                                                        PPPPaaaaggggeeee 11116666
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  1061.  
  1062.  
  1063.  
  1064.          sub FLAG_FOO ()     { 1 << 8 }
  1065.          sub FLAG_BAR ()     { 1 << 9 }
  1066.          sub FLAG_MASK ()    { FLAG_FOO | FLAG_BAR }
  1067.  
  1068.          sub OPT_BAZ ()      { not (0x1B58 & FLAG_MASK) }
  1069.          sub BAZ_VAL () {
  1070.              if (OPT_BAZ) {
  1071.                  return 23;
  1072.              }
  1073.              else {
  1074.                  return 42;
  1075.              }
  1076.          }
  1077.  
  1078.          sub N () { int(BAZ_VAL) / 3 }
  1079.          BEGIN {
  1080.              my $prod = 1;
  1081.              for (1..N) { $prod *= $_ }
  1082.              sub N_FACTORIAL () { $prod }
  1083.          }
  1084.  
  1085.      If you redefine a subroutine which was eligible for inlining you'll get a
  1086.      mandatory warning.  (You can use this warning to tell whether or not a
  1087.      particular subroutine is considered constant.)  The warning is considered
  1088.      severe enough not to be optional because previously compiled invocations
  1089.      of the function will still be using the old value of the function.  If
  1090.      you need to be able to redefine the subroutine you need to ensure that it
  1091.      isn't inlined, either by dropping the () prototype (which changes the
  1092.      calling semantics, so beware) or by thwarting the inlining mechanism in
  1093.      some other way, such as
  1094.  
  1095.          sub not_inlined () {
  1096.              23 if $];
  1097.          }
  1098.  
  1099.  
  1100.      OOOOvvvveeeerrrrrrrriiiiddddiiiinnnngggg BBBBuuuuiiiillllttttiiiinnnn FFFFuuuunnnnccccttttiiiioooonnnnssss
  1101.  
  1102.      Many builtin functions may be overridden, though this should be tried
  1103.      only occasionally and for good reason.  Typically this might be done by a
  1104.      package attempting to emulate missing builtin functionality on a non-Unix
  1105.      system.
  1106.  
  1107.      Overriding may be done only by importing the name from a module--ordinary
  1108.      predeclaration isn't good enough.  However, the subs pragma (compiler
  1109.      directive) lets you, in effect, predeclare subs via the import syntax,
  1110.      and these names may then override the builtin ones:
  1111.  
  1112.          use subs 'chdir', 'chroot', 'chmod', 'chown';
  1113.          chdir $somewhere;
  1114.          sub chdir { ... }
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                                                        PPPPaaaaggggeeee 11117777
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  1127.  
  1128.  
  1129.  
  1130.      To unambiguously refer to the builtin form, one may precede the builtin
  1131.      name with the special package qualifier CORE::.  For example, saying
  1132.      CORE::open() will always refer to the builtin open(), even if the current
  1133.      package has imported some other subroutine called &open() from elsewhere.
  1134.  
  1135.      Library modules should not in general export builtin names like "open" or
  1136.      "chdir" as part of their default @EXPORT list, because these may sneak
  1137.      into someone else's namespace and change the semantics unexpectedly.
  1138.      Instead, if the module adds the name to the @EXPORT_OK list, then it's
  1139.      possible for a user to import the name explicitly, but not implicitly.
  1140.      That is, they could say
  1141.  
  1142.          use Module 'open';
  1143.  
  1144.      and it would import the open override, but if they said
  1145.  
  1146.          use Module;
  1147.  
  1148.      they would get the default imports without the overrides.
  1149.  
  1150.      Note that such overriding is restricted to the package that requests the
  1151.      import.  Some means of "globally" overriding builtins may become
  1152.      available in future.
  1153.  
  1154.      AAAAuuuuttttoooollllooooaaaaddddiiiinnnngggg
  1155.  
  1156.      If you call a subroutine that is undefined, you would ordinarily get an
  1157.      immediate fatal error complaining that the subroutine doesn't exist.
  1158.      (Likewise for subroutines being used as methods, when the method doesn't
  1159.      exist in any of the base classes of the class package.) If, however,
  1160.      there is an AUTOLOAD subroutine defined in the package or packages that
  1161.      were searched for the original subroutine, then that AUTOLOAD subroutine
  1162.      is called with the arguments that would have been passed to the original
  1163.      subroutine.  The fully qualified name of the original subroutine
  1164.      magically appears in the $AUTOLOAD variable in the same package as the
  1165.      AUTOLOAD routine.  The name is not passed as an ordinary argument
  1166.      because, er, well, just because, that's why...
  1167.  
  1168.      Most AUTOLOAD routines will load in a definition for the subroutine in
  1169.      question using eval, and then execute that subroutine using a special
  1170.      form of "goto" that erases the stack frame of the AUTOLOAD routine
  1171.      without a trace.  (See the standard AutoLoader module, for example.)  But
  1172.      an AUTOLOAD routine can also just emulate the routine and never define
  1173.      it.   For example, let's pretend that a function that wasn't defined
  1174.      should just call _s_y_s_t_e_m() with those arguments.  All you'd do is this:
  1175.  
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.                                                                        PPPPaaaaggggeeee 11118888
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192. PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))                                                          PPPPEEEERRRRLLLLSSSSUUUUBBBB((((1111))))
  1193.  
  1194.  
  1195.  
  1196.          sub AUTOLOAD {
  1197.              my $program = $AUTOLOAD;
  1198.              $program =~ s/.*:://;
  1199.              system($program, @_);
  1200.          }
  1201.          date();
  1202.          who('am', 'i');
  1203.          ls('-l');
  1204.  
  1205.      In fact, if you predeclare the functions you want to call that way, you
  1206.      don't even need the parentheses:
  1207.  
  1208.          use subs qw(date who ls);
  1209.          date;
  1210.          who "am", "i";
  1211.          ls -l;
  1212.  
  1213.      A more complete example of this is the standard Shell module, which can
  1214.      treat undefined subroutine calls as calls to Unix programs.
  1215.  
  1216.      Mechanisms are available for modules writers to help split the modules up
  1217.      into autoloadable files.  See the standard AutoLoader module described in
  1218.      the _A_u_t_o_L_o_a_d_e_r manpage and in the _A_u_t_o_S_p_l_i_t manpage, the standard
  1219.      SelfLoader modules in the _S_e_l_f_L_o_a_d_e_r manpage, and the document on adding
  1220.      C functions to perl code in the _p_e_r_l_x_s manpage.
  1221.  
  1222. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  1223.      See the _p_e_r_l_r_e_f manpage for more on references.  See the _p_e_r_l_x_s manpage
  1224.      if you'd like to learn about calling C subroutines from perl.  See the
  1225.      _p_e_r_l_m_o_d manpage to learn about bundling up your functions in separate
  1226.      files.
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.                                                                        PPPPaaaaggggeeee 11119999
  1252.  
  1253.  
  1254.  
  1255.